package com.kfm.am;

public class StringExample {

    public static void main(String[] args) {
        String str1 = "kfm";
        String str2 = "KFM";

        System.out.println(str1.equals(str2)); // false
        System.out.println(str1.equalsIgnoreCase(str2)); // true

        System.out.println(str1.length()); // 字符串中 length() 是方法，在数组中 length 是属性

        System.out.println(str1.charAt(0));

        // int char 或者是字符对应的ASCII码
        System.out.println(str1.indexOf(97));
        System.out.println(str1.indexOf("ka"));
        // 从第二位开始找  “ka” 第一次出现的位置
        System.out.println(str1.indexOf("ka", 2));

        System.out.println(str1.lastIndexOf("a"));
        // 第2位是结束，找前面 a 最后一次出现的位置
        System.out.println(str1.lastIndexOf("a", 2));

        System.out.println(str1.startsWith("k"));
        System.out.println(str1.endsWith("l"));

        System.out.println("> <");
        // 大于 0 的值代表前者大，小于 0 的值代表后者大
        System.out.println(str1.compareTo(str2));
        // Upper() Lower()
        System.out.println("kaiFaMiao".toLowerCase()); // kaifamiao
        System.out.println("kaiFaMiao".toUpperCase()); // KAIFAMIAO
        System.out.println("kaifamiao".substring(2));
        // 从第二位开始截取到第四位结束
        System.out.println("kaifamiao".substring(2, 4));
//        String str = "   kaifamiao   ";
        String str = """  
                    kaifamiao    
                    nihao    
                """;
        System.out.println(str);
        System.out.println(str.length());
        // trim 去除两端空格
        String strTrim = str.trim();
        System.out.println("trim");
        System.out.println(strTrim);
        System.out.println(strTrim.length());
        // strip 去除两端空格
        String strStrip = str.strip();
        System.out.println("strip");
        System.out.println(strStrip);
        System.out.println(strStrip.length());
        // stripIndent 去除每一行的两端空格 去除前置最少得空格数量后面全部去掉
        String strStripIndent = str.stripIndent();
        System.out.println("stripIndent");
        System.out.println(strStripIndent);
        System.out.println(strStripIndent.length());
        // stripLeading 去除前置空格
        String strStripLeading = str.stripLeading();
        System.out.println("stripLeading");
        System.out.println(strStripLeading);
        System.out.println(strStripLeading.length());
        // stripTrailing 去除后置空格
        String strStripTrailing = str.stripTrailing();
        System.out.println("stripTrailing");
        System.out.println(strStripTrailing);
        System.out.println(strStripTrailing.length());
        System.out.println("=========");
        String string = "  nihao  \n   test  \n    hello  ";
        System.out.println(string);
        System.out.println(string.length());
        String string2 = string.stripIndent();
        System.out.println("======");
        System.out.println(string2);
        System.out.println(string2.length());
        String string3 = string.stripTrailing();
        System.out.println(string3);
        System.out.println(string3.length());

        String string4 = string.stripLeading();
        System.out.println(string4);
        System.out.println(string4.length());

        String string5 = string.trim();
        System.out.println(string5);
        System.out.println(string5.length());
        String string6 = string.strip();
        System.out.println(string6);
        System.out.println(string6.length());

    }
}
